//
//  ViewController.m
//  LoginDemo
//
//  Created by 解晓东 on 15/11/19.
//  Copyright (c) 2015年 sasa. All rights reserved.
//

#import "ViewController.h"

// 1.添加代理
@interface ViewController () <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;

@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation ViewController

- (IBAction)loginAction:(id)sender {
    NSLog(@"登录信息：");
    NSLog(@"用户名：%@", self.usernameTextField.text);
    NSLog(@"密码：%@", self.passwordTextField.text);
}

/**
 *  文本框代理实现方法，按回车键时执行。
 *
 *  @param textField 文本框本身
 *
 *  @return YES标示输入，否则不输入
 */
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    // 如果是usernameTextField，就跳到passwordTextField
    if (textField == self.usernameTextField) {
        [self.passwordTextField becomeFirstResponder];
    } else if (textField == self.passwordTextField) {
        // 如果是passwordTextField，就执行登录
        [self loginAction:nil];
        // 关闭键盘
        [self.passwordTextField resignFirstResponder];
    }
    
    return YES;
}

@end
